package com.hong.strategy.rpcserver;

import com.hong.Config.ConfigManager;
import com.hong.RpcServer;
import com.hong.config.constant.ServerConfig;
import com.hong.qrpc.constant.ProtoTypeConst;
import com.hong.qrpc.utils.StringUtils;
import com.hong.strategy.PropertiesStrategy;

import java.util.Map;

/**
 * @Author HQT
 * @Date 2022/8/10 9:21
 */
public class ProtocolTypeStrategy implements PropertiesStrategy {
    @Override
    public void disposeProperties(RpcServer rpcServer) {
        ConfigManager configManager = rpcServer.getConfigManager();
        Map<Object, Object> profile = configManager.getProfile();
        String protoType = (String) profile.get(ServerConfig.QRPC_PROTOCOL_TYPE);
        if (!StringUtils.isEmpty(protoType)) {
            if (ProtoTypeConst.isSupport(protoType)) {
                configManager.getRpcServerConfig().setProtocolType(ProtoTypeConst.getProtoTypeNum(protoType));
            } else {
                throw new IllegalArgumentException("unsupported protocol");
            }
        }
    }
}
